home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / DTS.Samples / SC16Aware / Event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-25  |  3.9 KB  |  144 lines  |  [04] ASCII Text (0x0000)

  1. /*
  2.     Event.c -- Version 3.0 
  3.     
  4.     Developer Technical Support Apple II Sample Code
  5.  
  6.     Copyright (c) 1990 by Apple Computer, Inc.
  7.     All Rights Reserved.
  8.  
  9.     Contains the main event loop for the network aware sample
  10.     application.  It also contains the routines to highlight
  11.     or dim menu items depending on whether a desk accessory
  12.     window is the front window.
  13. */
  14.  
  15. #include <Window.h>                     /* {CIIGSIncludes}Window.h */
  16. #include <Menu.h>                       /* {CIIGSIncludes}Menu.h */
  17. #include "Aware.h"
  18.  
  19.  
  20. extern int quitFlag;
  21. extern WmTaskRec event;
  22. extern GrafPortPtr lastWindow;
  23.  
  24.  
  25. /*
  26.     enableDAItems()
  27.     
  28.     This routine enables the menu items and menus necessary
  29.     when a desk accessory is in the frontmost window.  In our
  30.     case, it enables the Close item in the File menu, and
  31.     enables the Edit menu.
  32. */
  33. void    enableDAItems()
  34. {
  35.     EnableMItem(CloseItem);
  36.     SetMenuFlag(0xFF7F, EditMenuID);        /* enable the edit menu */
  37. }
  38.  
  39.  
  40.  
  41. /*
  42.     enableApplItems()
  43.     
  44.     This routine enables the menu items and menus necessary
  45.     when a desk accessory is not in the frontmost window.
  46.     In our case, it enables the Load Configuration and
  47.     Save Configuration items in the File menu.
  48. */
  49. void    enableAppItems()
  50. {
  51.     EnableMItem(LoadConfigItem);
  52.     EnableMItem(SaveConfigItem);
  53. }
  54.  
  55.  
  56. /*
  57.     disableDAItems()
  58.     
  59.     This routine disables the menu items and menus used by
  60.     a desk accessory.  In our case, it disables the Close
  61.     item in the File menu and disables the Edit menu.
  62. */
  63. void    disableDAItems()
  64. {
  65.     DisableMItem(CloseItem);
  66.     SetMenuFlag(0x0080, EditMenuID);        /* disable the edit menu */
  67. }
  68.  
  69.  
  70. /*
  71.     disableApplItems()
  72.     
  73.     This routine disables the menu items and menus used by
  74.     the main application.  In our case, it disables the
  75.     Load Configuration and Save Configuration options in the
  76.     File menu.
  77. */
  78. void    disableAppItems()
  79. {
  80.     DisableMItem(LoadConfigItem);
  81.     DisableMItem(SaveConfigItem);
  82. }
  83.  
  84.  
  85.  
  86. /*
  87.     checkFrontW()
  88.     
  89.     This routine determines which window (if any) is frontmost
  90.     and updates the menu items as necessary.
  91. */
  92. void    checkFrontW()
  93. {
  94.     GrafPortPtr     theWindow;
  95.  
  96.     theWindow = FrontWindow();
  97.  
  98.     /*  If the front window hasn't changed since the last time
  99.         we checked, then there is no need to change the menu
  100.         items. */
  101.     if (theWindow == lastWindow) return;
  102.  
  103.     if (!theWindow) {           /* If no front window... */
  104.         disableDAItems();       /* Turn off desk accessory items */
  105.         enableAppItems();       /* Turn on the application's items */
  106.     }
  107.     else {                      /* Look at what kind of window we have... */
  108.         if (GetSysWFlag(theWindow)) {
  109.             /* It's a DA */
  110.             disableAppItems();  /* Turn off the application's items */
  111.             enableDAItems();    /* Turn on the DA items */
  112.         }
  113.         else {
  114.             /* A window other than a DA window */
  115.             disableDAItems();   /* Turn off DA items */
  116.             enableAppItems();   /* Turn on application items */
  117.         }
  118.     }
  119.  
  120.     DrawMenuBar();              /* Redraw menu bar to reflect the changes */
  121.     lastWindow = theWindow;     /* Remember which window it was */
  122. }
  123.  
  124.  
  125.  
  126. /*
  127.     mainEvent()
  128.     
  129.     This is the event loop of our sample application.  It's quite
  130.     simple because TaskMaster handles almost everything for us.
  131. */
  132. void mainEvent()
  133. {
  134.     while (!quitFlag) {                 /* Repeat until user selects Quit */
  135.         checkFrontW();                  /* set menus according to front window */
  136.         switch(TaskMaster(0xFFFF, &event)) {    /* Have TaskMaster handle an event */
  137.             case wInSpecial:            /* Was it a menu item for a DA? */
  138.             case wInMenuBar:            /* Or in the menu bar? */
  139.                 doMenu();               /* Yes, so handle the menu selection */
  140.                 break;                  /* and exit the switch() statement */
  141.         }
  142.     }
  143. }
  144.